package jFeature.analysis;

import org.apache.commons.lang3.StringUtils;

public class TraceabilityMatrix {
	private static final char MARKER = '*';
	public char[] matrix ;
	public int[]  tangling ;
	public int[]  scattering ;
	public int featureSize = 0 ;
	public int classSize = 0 ;
	public TraceabilityMatrix(Analysis analysis) {
		ElementMap featureMap = analysis.getFeatureMap() ;
		ElementMap classMap = analysis.getClassMap() ;
		featureSize = featureMap.size() ;
		classSize = classMap.size() ;
		String tmp = StringUtils.repeat(" ", featureSize * classSize);
		matrix = tmp.toCharArray() ;
		tangling = new int[classSize] ;
		scattering = new int[featureSize] ;
		for(int i=0;i<classSize;i++) {
			tangling[i] = 0 ;
		}
		for(int i=0;i<featureSize;i++) {
			scattering[i] = 0 ;
		}
		
		for(ElementNode featureNode : featureMap.nodes) {
			for(ElementNode classNode : featureNode.nodes) {
				int index = getIndex(featureNode.id, classNode.id);
				matrix[index] = MARKER ;
				tangling[classNode.id-1] += 1 ;
				scattering[featureNode.id-1] += 1 ;
			}
		}
	}
	private int getIndex(int featureNodeId, int classNodeId) {
		int index = featureNodeId - 1 + featureSize * (classNodeId - 1 );
		return index ;
	}
	public boolean getTraceability(int featureId, int  classId) {
		int index = getIndex(featureId,classId) ;
		if(matrix[index]==MARKER) {
			return true ;
		}
		return false ;
	}
	
}
